#!/usr/bin/env python
#-*- coding:utf-8 -*-

'''
Pentestdb, a database for penetration test.
Copyright (c) 2015 alpha1e0
'''


import os
from setuptools import setup, find_packages



def generate_default_config_file():
    from appdirs import AppDirs

    dirs = AppDirs("pentestdb","alpha1e0")

    cfgdir = dirs.user_config_dir
    if not os.path.exists(cfgdir):
        os.makedirs(cfgdir)
    cfgfile = os.path.join(cfgdir, "pentestdb.conf")

    currentpath = os.getcwd()
    ptdatapath = os.path.dirname(currentpath)

    content = "[basic]\ndatapath={}".format(ptdatapath)

    try:
        with open(cfgfile, 'w') as _file:
            _file.write(content)
    except IOError as error:
        print u"[!]: 安装pentestdb失败，写入配置文件'{0}'失败，原因：{1}".format(
            cfgfile, str(error))
        exit(1)


def get_requirements():
    result = []
    with open('requirements.txt') as _file:
        for line in _file:
            if line.startswith("#") or "--index" in line:
                continue

            result.append(line)

    return result


setup(
    name = "pentestdb",
    version = "1.1.0",
    author = "alpha1e0",
    author_email = "yan.shifm@foxmail.com",
    description = "Tools and Resources for Web Penetration Test",
    url = "https://github.com/alpha1e0/pentestdb",

    packages = find_packages(exclude=['exploit']),
    include_package_data = True,
    entry_points = {
        'console_scripts': [
            'pentest = pentest.penfuncs:main',
            'pen-mail = pentest.mail:main',
            'pen-wordlist = pentest.wordlist:main',
        ]
    },
    install_requires = get_requirements()
)


try:
    generate_default_config_file()
except Exception as error:
    print u"[!]: 安装pentestdb失败，原因：{}".format(str(error))
    exit(1)